<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<link rel="stylesheet" href="../../assets/css/layui.css">
		<link rel="stylesheet" href="../../assets/css/view.css"/>
		<title></title>
		<script>
			function resetData() {
				$("input").val("");
			}
		</script>
	</head>
	<body class="layui-view-body">
		<div class="layui-content">
			<div class="layui-row">
				<div class="layui-card">
					<div class="layui-card-header">添加快递员</div>
					<form id="iForm" class="layui-form layui-card-body">
						<div class="layui-form-item">
							<label class="layui-form-label">姓名</label>
							<div class="layui-input-block">
								<input type="text" name="code" required lay-verify="required" placeholder="请输入姓名(1-32位有效字符)"
									   autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">手机号码</label>
							<div class="layui-input-block">
								<input type="text" name="phonenumber" required lay-verify="required" placeholder="请输入手机号码"
									   autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">身份证号码</label>
							<div class="layui-input-block">
								<input type="text" name="username" required lay-verify="required" placeholder="请输入身份证号码"
									   autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">密码</label>
							<div class="layui-input-block">
								<input type="text" name="phonenumber" required lay-verify="required" placeholder="请输入密码(6-32位有效字符)"
									   autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-input-block">
								<button class="layui-btn layui-btn-blue" lay-submit lay-filter="formDemo" id="btn">立即提交</button>
								<button type="reset" class="layui-btn layui-btn-primary" onclick="resetData()">重置</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
		<script src="../../assets/layui.all.js"></script>
		<script src="/js/jquery2.1.4.js"></script>
		<script src="/layer/layer.js"></script>
		<script>
			$(function () {
				$("#iForm").submit(function () {
					var windowId = layer.load();
					var name = $("input:eq(0)").val();
					var phone = $("input:eq(1)").val();
					var idCard = $("input:eq(2)").val();
					var password = $("input:eq(3)").val();
					$.post("/courier/insert.do", {
						name: name,
						phone: phone,
						idCard: idCard,
						password: password
					}, function (data) {
						layer.close(windowId);
						layer.msg(data.content);
						if (data.status === 0) {
							resetData();
						}
					}, "JSON");
					return false;
				});
				$("input:eq(0)").blur(function () {
					var str = $(this).val();
					if (str.trim() === "") {
						layer.msg("姓名不能为空！");
						$(this).focus();//选中
						$(this).select();//全选
						$("#btn").prop("disabled", true);
					}else {
						if (str.match(/^[\u4e00-\u9fff\w]{1,32}$/) === null) {
							layer.msg("姓名不合法！");
							$(this).focus();//选中
							$(this).select();//全选
							$("#btn").prop("disabled", true);
						}else {
							$("#btn").prop("disabled", false);
						}
					}
				});
				$("input:eq(1)").blur(function () {
					var str = $(this).val();
					if (str.trim() === "") {
						layer.msg("手机号码不能为空！");
						$(this).focus();//选中input输入框
						$(this).select();//全选input输入框内输入内容
						$("#btn").prop("disabled", true);
					}else {
						if (str.match(/^1[3-9]\d{9}$/) === null) {
							layer.msg("请输入正确的手机号码！");
							$(this).focus();//选中input输入框
							$(this).select();//全选input输入框内输入内容
							$("#btn").prop("disabled", true);
						}else {
							$("#btn").prop("disabled", false);
						}
					}
				});
				$("input:eq(2)").blur(function () {
					var str = $(this).val();
					if (str.trim() === "") {
						layer.msg("身份证号码不能为空！");
						$(this).focus();//选中input输入框
						$(this).select();//全选input输入框内输入内容
						$("#btn").prop("disabled", true);
					}else {
						if (str.match(/^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/) === null) {
							layer.msg("请输入正确的身份证号码！");
							$(this).focus();//选中input输入框
							$(this).select();//全选input输入框内输入内容
							$("#btn").prop("disabled", true);
						}else {
							$("#btn").prop("disabled", false);
						}
					}
				});
				$("input:eq(3)").blur(function () {
					var str = $(this).val();
					if (str.trim() === "") {
						layer.msg("密码不能为空！");
						$(this).focus();//选中input输入框
						$(this).select();//全选input输入框内输入内容
						$("#btn").prop("disabled", true);
					}else {
						if (str.match(/^[A-Za-z0-9_]{6,32}$/) === null) {
							layer.msg("密码不合法！");
							$(this).focus();//选中input输入框
							$(this).select();//全选input输入框内输入内容
							$("#btn").prop("disabled", true);
						}else {
							$("#btn").prop("disabled", false);
						}
					}
				});
			})
		</script>
	</body>
</html>
